/**
 * 代码编辑框的工具条
 * @param {} config
 */
DC.front.EditorToolbar = function(params, config) {
	var editor_toolbar = this;
	
	var code_formPanel_id = '_form_panel';
	if (params) {
		code_formPanel_id = params.codeFormPanelId;
	}
	 
	
	// 保存当前页面代码
	var save = new Ext.Button({
		iconCls: 'save_icon',
		cls : 'save',
		tooltip: '保存',
		//disabled : true,
		handler :function() {
			editor_toolbar.exeCmd('save');
		}
	});
	// undo按钮
	var undo = new Ext.Button({
		iconCls: 'undo_icon',
		tooltip: '回退',
		//disabled : true,
		handler :function() {
			editor_toolbar.exeCmd('undo');
		}
	});
	// redo按钮
	var redo = new Ext.Button({
		iconCls: 'redo_icon',
		tooltip: '重做',
		//disabled : true,
		handler :function() {
			editor_toolbar.exeCmd('redo');
		}
	});
	// language下拉列表
	var languageCombo = new Ext.form.ComboBox({
    	name: 'language',
    	hiddenName: 'language', // 提交到后台的input的name，重要
    	width: 90,
    	editable: false,
    	triggerAction: 'all', // 显示所有下列数据，一定要设置属性triggerAction为all
        //allowBlank: false, //不允许为空
    	store: new Ext.data.SimpleStore({
    		fields: ['name', 'value'],
    		data: [
				['--语法--', 'grammar'],
				['Java', 'java'],
				['HTML', 'html'],
				['CSS', 'css'],
				['Javascript', 'javascript']
			]
    	}),
    	displayField: 'name',
    	valueField: 'value',
    	mode: 'local',
    	emptyText: 'Java',
    	listeners:{
            select:{
                fn:function(combo,record,index) {
                	var comValue = record.get('value');
                	if (comValue == 'java') {
                		
                	}
               }
            }
        }

	});
	DC.front.EditorToolbar.superclass.constructor.call(this, Ext.apply({
		height: 25,
		margins: '0 0 0 0',
		region: 'north',
		items: [ save, '-', undo, redo, '-', languageCombo ]
    }, config ||{}));
    
    /*
     *绑定事件 
     */
    //save.on('click', this.exeCmd('save'));
};

Ext.extend(DC.front.EditorToolbar, Ext.Toolbar, {
	exeCmd : function(cmd) {
		if (DC.obj.editor_tabPanel != null) {
			var code_field = Ext.getCmp(DC.obj.editor_tabPanel.getActiveTab().getId() + '_field');
			switch (cmd) {
			case 'undo':
				this.undo(code_field);
				break;
			case 'redo':
				this.redo(code_field);
				break;
			case 'save':
				this.save(code_field);
				break;
			}
		}
		
	},
	
	undo : function(field) {
        field.undo();
	},
	
	redo : function(field) {
		field.redo();
	},
	
	save : function(field) {
		DC.action.SysAction.saveFile(field);
	}
});